/*********** NOTES HEADER *********** 

DESCRIPTION: This file produces the graphs for the lead/lag estimates

************************************/ 

set more off
capture log close
clear all

	use ll_death_small.dta
		rename rnglaucoma rownames
		order rownames
		capture drop rn* id
		gen id=_n-1
		replace id=id+1 if _n>16
		keep id rownames mem* mef*
		replace id=16 if _n==34
		drop if id>32
		sort id
		order id
		drop rownames 
		  
		reshape long mem_beta_ mem_sesq_ mef_beta_ mef_sesq_ , i(id) j(depvar) str

		replace depvar = substr(depvar,1,length(depvar)-2)


		gen leadlag = id
		replace leadlag = leadlag - 16

		rename mem_beta_ beta_Male
		rename mef_beta_ beta_Female
		rename mem_sesq_ sesq_m
		rename mef_sesq_ sesq_f

		gen uFemale95=beta_Female+sqrt(sesq_f)*2
		gen lFemale95=beta_Female-sqrt(sesq_f)*2

		gen uMale95=beta_Male+sqrt(sesq_m)*2
		gen lMale95=beta_Male-sqrt(sesq_m)*2

			foreach var of varlist *Female* *Male* {
			 replace `var' = 0 if `var' ==.
			 }

		 replace depvar = trim(depvar)
		 replace depvar=regexr(depvar,"_","")

		gen dvar="Acute cardiac" if depvar=="acuteicd8"
		 replace dvar="AMI" if depvar=="ami"                                         
		 replace dvar="Congestive heart failure" if depvar=="chf"
		 replace dvar="Mortality" if depvar=="death"                                         
		 replace dvar="Diabetes complications" if depvar=="diabcomp" 
		 replace dvar="Asymptomatic diabetes complications " if depvar=="diabcomp1"                                         
		 replace dvar="Symptomatic diabetes complications " if depvar=="diabcomp2"                                         
		 replace dvar="Glaucoma " if depvar=="glaucoma"
		 replace dvar="Ischemic heart disease " if depvar=="ihd"
		 replace dvar="Malignant Hypertension " if depvar=="malighyp"                                         

		drop if leadlag < -14
		drop if leadlag >  14

		graph set window fontface "Times New Roman"
		graph set ps fontface "Times New Roman"

		label var beta_Male "Male"
		label var beta_Female "Female"

			foreach sex in "Male" "Female" {
			 foreach i in "diabcomp2"  "ami" "death" {
			  levelsof dvar if depvar=="`i'", local(k)

			  twoway line l`sex'95 beta_`sex' u`sex'95 leadlag if depvar=="`i'" , subtitle(`sex') xtitle("Quarters since merger", size(small) margin(t .5))  ytitle(`k', margin(r 1 l -1) axis(1) size(small))  lp(shortdash solid shortdash) saving(g`i'_`sex', replace)  graphregion(color("white")) scheme(s2mono) legend(off) xline(0)  
			 }

			 foreach i in "diabcomp1"   "glaucoma"  "acuteicd8"   "ihd"  {
			  levelsof dvar if depvar=="`i'", local(k)

			   twoway line l`sex'95 beta_`sex' u`sex'95 leadlag if depvar=="`i'" , subtitle(" ") xtitle("Quarters since merger", size(small) margin(t .5))  ytitle(`k', margin(r 1 l -1) axis(1) size(small))  lp(shortdash solid shortdash) saving(g`i'_`sex', replace)  graphregion(color("white")) scheme(s2mono) legend(off) xline(0)  
			 }
			}

   
		graph combine gdiabcomp1_Male.gph gdiabcomp2_Male.gph gglaucoma_Male.gph  gdiabcomp1_Female.gph gdiabcomp2_Female.gph gglaucoma_Female.gph, col(3) ycommon xcommon  graphregion(color("white")) 
		graph export "./PS_DiabetesMW.ps", as(ps) orientation(landscape) lmargin(.05) tmargin(.3) mag(200) logo(off) replace

		graph combine gacuteicd8_Male.gph gami_Male.gph gihd_Male.gph  gacuteicd8_Female.gph gami_Female.gph gihd_Female.gph   , col(3) ycommon xcommon  graphregion(color("white"))
		graph export "./PS_HypertensionMW.ps", as(ps) orientation(landscape) lmargin(.05) tmargin(.3) mag(200) logo(off) replace

		graph combine gdeath_Male.gph gdeath_Female.gph , col(1) ycommon xcommon graphregion(color("white")) 
		graph export "./PS_DeathMW.ps", as(ps) orientation(landscape) lmargin(.05) tmargin(.3) mag(200) logo(off) replace 
